//
//  TestView.m
//  sandbox
//
//  Created by 杨岑 on 1/5/15.
//  Copyright (c) 2015 杨岑. All rights reserved.
//

#import "TestView.h"

@implementation TestView

- (void)updateTrackingAreas
{
    for (NSTrackingArea* a in self.trackingAreas)
    {
        [self removeTrackingArea:a];
    }
    
    NSTrackingAreaOptions options = NSTrackingMouseMoved
        + NSTrackingActiveInKeyWindow
        + NSTrackingMouseEnteredAndExited;
    NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
                                                options:options
                                                  owner:self
                                               userInfo:nil];
    [self addTrackingArea:trackingArea];
}

- (void)mouseMoved:(NSEvent *)theEvent
{
    _time = 0;
}

- (void)mouseExited:(NSEvent *)theEvent
{
    NSLog(@"%@ mouse exit", self);
    _time = 0;
}

- (void)mouseEntered:(NSEvent *)theEvent
{
    NSLog(@"%@ mouse enter", self);
    _time = 0;
}

- (void)mouseUp:(NSEvent *)theEvent
{
    
}

- (void)drawRect:(NSRect)dirtyRect
{
    [[NSColor clearColor] set];
    NSRectFill(self.bounds);
    
    NSRect rect = self.bounds;
    rect.origin.y = 20;
    NSColor* c = [NSColor colorWithRed:0 green:0 blue:0 alpha:.6];
    [c set];
    NSRectFill(rect);
    
    [[NSColor cyanColor] set];
    rect = NSMakeRect(0, 0, 80, 20);
    NSRectFill(rect);
}

@end
